/**
 * 
 */
package weibo4j.examples;

import weibo4j.Users;
import weibo4j.examples.oauth2.Log;
import weibo4j.http.HttpClient;
import weibo4j.model.PostParameter;
import weibo4j.model.WeiboException;
import weibo4j.org.json.JSONArray;
import weibo4j.org.json.JSONObject;
import weibo4j.util.WeiboConfig;

/**
 * 用户
 * @author Administrator
 * 用户接口
 */
public class WeiboUser {
	public static void showByScreenName(String access_token,String name){
		try {
			Users user = new Users();
			user.client.setToken(access_token);
			weibo4j.model.User user_ = user.showUserByScreenName(name);
			Log.logInfo(user_.toString());
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//获取用户信息
	public static void show(String access_token,String uid){
		try {
			Users user = new Users();
			user.client.setToken(access_token);
			weibo4j.model.User user_ = user.showUserById(uid);
			Log.logInfo(user_.toString());
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//获取用户等级信息
	public static void show_rank(String access_token,String uid){
		try {
			HttpClient client = new HttpClient();
			client.setToken(access_token);
			JSONObject result = client.get(WeiboConfig.getValue("baseURL")+"users/show_rank.json",new PostParameter[]{
				new PostParameter("uid", uid)
			}).asJSONObject();
			Log.logInfo(result.toString());
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//通过个性域名获取用户信息 
	public static void domain_show(String access_token,String domain){
		try {
			Users user = new Users();
			user.client.setToken(access_token);
			weibo4j.model.User user_ = user.showUserByDomain(domain);
			Log.logInfo(user_.toString());
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	//批量获取用户的粉丝数、关注数、微博数 
	public static void counts(String access_token,String uid){
		try {
			Users user = new Users();
			user.client.setToken(access_token);
			JSONArray user_ = user.getUserCount(uid);
			Log.logInfo(user_.toString());
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String access_token = WeiboContants.access_token;
		String uid =WeiboContants.uid;
		String domain =WeiboContants.domain;
		//show(access_token,"小白的钱钱");
		//show(access_token,uid);
		//counts(access_token,uid);
		domain_show(access_token,"babyqian84");
		//show_rank(access_token,uid);
	}

}
